<?php
class TestApiController extends BackOfficeController
{
    public function getservices()
    {
        return array(
            // core services
            'Core.WebApi.getToken' => array(),
            'Cms.Site.getSupportedLanguages' => array(),
//                'Filly.user.getUserId'=> array(),
            'Filly.user.getUserSessionId' => array(),

            // login, register, account modification
            'User.User.login' => array(
                'User[email]' => 'your@email.com',
                'User[password]' => '12345'
            ),
            'User.User.logout' => array(
            ),
            'User.User.transferAccount' => array(
                'User[email]' => 'your@email.com',
                'User[password]' => '12345',
                'User[name1]' => '',
                'User[name2]' => '',
                'User[name3]' => '',
                'User[birth_month]' => '',
                'User[birth_date]' => '',
                'User[confirmPassword]' => '',
                'User[is_over_13]' => '',
                'User[parent_email]' => ''
            ),
            'User.User.getUserNameOptions' => array(
            ),
            'User.User.resendConfirmEmail' => array(
                'User[email]' => 'your@email.com',
            ),
            'Filly.User.resetPassword' => array(
                'User[email]' => ''
            ),

            'Filly.User.changePassword' => array(
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
                'password' => '123456',
            ),

            'Filly.User.updateAccountInfo' => array(
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
                'User[email]' => '',
                'User[password]' => 'abcde',
                'User[birth_month]' => 5,
                'User[birth_date]' => 10
            ),
            'Filly.User.getAccountInfo' => array(
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
            ),

            'eCommerce.Product.productList' => array(
                'category' => ''
            ),
            'eCommerce.Product.productCategories' => array(
                'catalog' => ''
            ),
            'eCommerce.Product.productCatalog' => array(
            ),
            // get or set generic data
            'Filly.FlashObject.setData' => array(
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
                'FlashObject[owner_id]' => Yii::app()->session->get('UserSessionId', ''),
                'FlashObject[id]' => '',
                'FlashObject[type]' => '',
                'FlashObject[data]' => '',
            ),

            'Filly.FlashObject.clearGuestData' => array(
            ),

            'Filly.FlashObject.getData' => array(
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
                'FlashObject[owner_id]' => Yii::app()->session->get('UserSessionId', ''),
                'FlashObject[id]' => '',
                'FlashObject[type]' => '',
            ),
            // update data
            'Filly.FlashObject.updateData' => array(
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
                'FlashObject[owner_id]' => Yii::app()->session->get('UserSessionId', ''),
                'FlashObject[id]' => '',
                'FlashObject[type]' => '',
                'FlashObject[data]' => '',
            ),

            // list (taxonomy)
            'Core.Taxonomy.getList' => array(
                'module' => 'Filly',
                'type' => '',
                'root' => null,
                'state' => 1
            ),

            // filly
            'Filly.FlashObject.randomFillyName' => array(
                'type' => 'unicorn',
            ),

            // pageant
            'Pageant.Pageant.registerFilly' => array(
                'FlashObject[id]' => '',
            ),
            'Pageant.Pageant.isRegistered' => array(
                'FlashObject[id]' => '',
            ),
            'Pageant.Pageant.unregisterFilly' => array(
                'PageantFilly[id]' => '',
            ),
            'Pageant.Match.getPairs' => array(
                //'number_of_pairs' => 3,
                //'exclude' => '',
                //'start_match_no' => 1,
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
                'number_of_matches' => 1,
            ),
            'Pageant.Match.vote' => array(
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
                'id' => ''
            ),
            'Pageant.Pageant.getRewardTotal' => array(
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
            ),
            'Pageant.Pageant.getNumberOfVotes' => array(
                'id' => ''
            ),
            'Pageant.Pageant.getFillyRank' => array(
                'pageant_id' => '',
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
            ),

            // generate matchs
            'Pageant.Match.generateMatches' => array(
                'pageant_id' => '',
                'number_of_matches' => 1,
            ),

            // get total votes in last pageant
            'Filly.Pageant.getTotalVotesInLastPageant' => array(
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
            ),

            // get votes of 2 fillies in a match
            'Pageant.Pageant.getMatchVotes' => array(
                'match_no' => '',
            ),

            // get top fillies in a pageant 
            'Pageant.Pageant.getTopFillies' => array(
                'pageant_id' => '',
            ),

            // get new messages 
            'Site.Message.getNewMessage' => array(
                'user_session_id' => Yii::app()->session->get('UserSessionId', ''),
            ),
        );
    }


    public function getGuestAllowedActions()
    {
        return array('index', 'prepare', 'v2', 'blank');
    }

    public function actionIndex()
    {
        //        if (Yii::app()->request->getIsPostRequest()) {
        //
        //        }
        $this->render('form');
    }

    public function actionV2()
    {
        Yii::app()->layout = null;
        $this->render('formV2');
    }

    public function actionPrepare()
    {
        $token = $this->post('token', '');
        $t = $this->post('t', 0);
        $key = Settings::WEB_API_PUBLIC_KEY;

        $hash = md5($token . $key . $t);

        echo CJavaScript::jsonEncode(array('t' => date('d-m-Y h:i:s', $t), 'hash' => $hash));
    }

    public function actionBlank()
    {
        echo '<html><body><form method="post" id="service-form"></form></body></html>';
    }
}

?>
